package com.zhaoxi.project.fms.service;

import com.zhaoxi.framework.web.PageData;
import com.zhaoxi.framework.web.BaseService;
import com.zhaoxi.project.fms.mapper.BillMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 财务单据Service业务层处理
 */
@Service
public class BillService extends BaseService {
  @Autowired
  private BillMapper billMapper;

  //查询数据集合
  public List<PageData> getList(PageData pd) {
    return billMapper.getList(pd);
  }

  //查询数据对象 通过id
  public PageData getById(PageData pd) {
    PageData pd1 = new PageData();
    if (pd.getLong("id") == null){
      return null;
    }
    pd1.put("id",pd.getLong("id"));
    List<PageData> list = billMapper.getList(pd1);
    if (list.size() > 0){
      return list.get(0);
    }
    return null;
  }

  //查询数据行数
  public PageData getCount(PageData pd) {
    
    return this.success(billMapper.getCount(pd));
   
  }

  //新增
  public PageData add(PageData pd) {
    
    pd.put("createBy", this.getUsername());
    return this.responses(billMapper.add(pd));
  }

  //更新
  public PageData edit(PageData pd) {
    
    pd.put("updateBy", this.getUsername());
    return this.responses(billMapper.edit(pd));
  }

  //删除
  public PageData del(Long id) {
    
    return this.responses(billMapper.del(id));
  }

  //单据类别查询1
  public List<PageData> getTypeList(PageData pd) {
    return billMapper.getTypeList(pd);
  }

  //查询数据对象 通过id
  public PageData getTypeById(PageData pd) {
    PageData pd1 = new PageData();
    if (pd.getLong("typeId") == null){
      return null;
    }
    pd1.put("typeId",pd.getLong("typeId"));
    List<PageData> list = billMapper.getTypeList(pd1);
    if (list.size() > 0){
      return list.get(0);
    }
    return null;
  }
}